<?php

$mysqli=new mysqli('localhost','morteza','tak','my_db') or die ("Connetion error!");


$f_name=$_POST['f_name'];
$l_name=$_POST['l_name'];
$email=$_POST['email'];
$mobile=$_POST['mobile_no'];
$department=$_POST['department'];
$file_name='';




if ($_FILES['image']['error']>0) {
	echo "Error: ". $_FILES['image']['error'];
}

else
{
	$pos=strrpos($_FILES['image']['name'], '.');
	$suffix=substr($_FILES['image']['name'], $pos);
	$file_name=time()+rand().$suffix;
	move_uploaded_file($_FILES['image']['tmp_name'], 'upload/'.$file_name);
}

$query = " insert into my_db.std(name,lname,email,department,mobile,img) values('$f_name','$l_name','$email','$department',$mobile,'$file_name') ";
$res=$mysqli->query($query);

if ($res) {
    header('location:index.php?status=success');
}

else {
    header('location:index.php?status=failed');
}

?>